#ifndef _THREAD_GROUP_H_
#define _THREAD_GROUP_H_

namespace share
{

class Thread_Group
{
public:
	Thread_Group( void );

	~Thread_Group( void );

	Thread *create_thread( );

	template < class TFUNC >
	void run_thread( TFUNC func, int thread_num = 1 )
	{
		Thread *pThread;

		for( int i = 0; i < thread_num; i ++ )
		{
			pThread = create_thread( );
			pThread->thread_func( func );
			pThread->start( );
		}
	}

	template < class TOBJPTR, class TOBJ_FUNC_PTR >
	void run_thread( TOBJPTR objptr, TOBJ_FUNC_PTR func, int thread_num = 1 )
	{
		run_thread( std::pair< TOBJPTR, TOBJ_FUNC_PTR > ( objptr, func ), thread_num );
	}

	void join_all( );

	void add_thread( Thread *thread );

	void remove_thread( Thread *thread );

private:

	list< Thread* > threads_;
	Thread_Mutex	mutex_;
};

}
#endif
